package com.dl.designmodel.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: mcroservices
 * @Package: com.dl.designmodel.observer
 * @ClassName: ObjectFor3D
 * @Author: 86977
 * @Description: ${description}
 * @Date: 2021/6/29 14:30
 * @Version: 1.0
 */
public class ObjectFor3D implements Subject {
  private List<Observer>observerList =new ArrayList<>();
  /**
   * 3D彩票的号码
   */
  private String msg;

  @Override
  public void registerObserver(Observer observer) {
    observerList.add(observer);
  }

  @Override
  public void removeObserver(Observer observer) {

    int index=observerList.indexOf(observer);
    if(index>0){
      observerList.remove(observer);
    }
  }

  @Override
  public void notifyObservers() {
    for (Observer observer:observerList){
      observer.update(msg);
    }
  }

  public void setMsg(String msg) {
    this.msg = msg;
    notifyObservers();
  }
}
